package org.example.design.chain.controller;

import org.example.design.chain.bean.AuthInfo;
import org.example.design.chain.service.AuthService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname AuthController
 * @Description TODO
 * @Date 2020/11/6 10:19 上午
 * @Created by xiangjd
 */
public class AuthController {
    private SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public AuthInfo doAuth(String uid, String orderId, Date authDate) throws ParseException {

        // 三级审批
        Date date = AuthService.queryAuthInfo("1000013", orderId);
        if (null == date) {
            return new AuthInfo("0001", "单号：", orderId, " 状态：待三级审批负责人 ", "王工");
        }
        //二级审批
        if (authDate.after(f.parse("2020-11-01 00:00:00")) && authDate.before(f.parse("2020-11-25 23:59:59"))) {
            date = AuthService.queryAuthInfo("1000012", orderId);
            if (null == date) {
                return new AuthInfo("0001", "单号", orderId, "状态：待二级审批负责人 ", "张经理");
            }
        }
        //三级审批
        if (authDate.after(f.parse("2020-11-05 00:00:00")) && authDate.before(f.parse("2020-11-20 23:59:59"))) {
            date = AuthService.queryAuthInfo("1000011", orderId);
            if (null == date) {
                return new AuthInfo("0001", "单号", orderId, "状态：待一级审批负责人 ", "王总监");
            }
        }

        return new AuthInfo("0001", "单号", orderId, "状态：审批完成");
    }
}
